package innovacion.servlet.idea;

import innovacion.negocio.GestionIdea;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class IdeaPublicarServlet
 */
@WebServlet("/IdeaPublicarServlet")
public class IdeaPublicarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public IdeaPublicarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		GestionIdea negocio = new GestionIdea();
		System.out.println("-----");
		String [] ideas= request.getParameterValues("checkidea");
		
		try{
			if (ideas!= null && ideas.length>0) {
			    for (int i = 0; i < ideas.length; i++) {
			    	int idea=Integer.parseInt(ideas[i]);
			    	negocio.actualizar_estado(idea);					
			    }
			    request.setAttribute("mensaje","1" );
			  } else {
				  System.out.println ("seleccione Idea");
				  request.setAttribute("mensaje","3" );
				  }
			
			RequestDispatcher rd = request.getRequestDispatcher("publicar_ideas.jsp");
			rd.forward(request, response);
		} catch (Exception e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}

		
		
		
		
		
		
		
	}

}
